//加入淘号吧代码
function show_add(){
		$('#list_ul_li ul li').each(function(i,dom){
			if($(dom).css('display') != 'none'){
				if(i != '0'){
					$(dom).css('display','none');
				}else {
					$(dom).css('border','0px');
					$('#list_ul_li ul li:eq(0) span:eq(0)').attr('class','clearfix');
				}
			}else{
				$(dom).css('display','');
					var arr = '1px #d2d1d1 solid';
					$('#list_ul_li ul li:eq(0)').css('border-bottom',arr);
					$('#list_ul_li ul li:eq(0) span:eq(0)').attr('class','clearfix_copy');
			}
		});
	}
function check_show1(_id){
////$(this).removeClass("tow").addClass("one");
	_index = _id.substr(8);//去址前8位
	//取谐斜某
	var li_length = $('.ul_li:gt(0):eq(0) span').length +$('.ul_li:gt(0):eq(1) span').length;
	for(var i=-1;i<li_length;i++){
		$('#showshow'+i).removeClass("arr2").addClass("arr1");
	}
	//$('#showshowX').removeClass("arr2").addClass("arr1");
	$('#showshow'+_index).removeClass("arr1").addClass("arr2");
	var arr = $('#'+_id).html();
	$('#showshow').html(arr);
	$('#showshow').removeClass("arr1").addClass("arr2");
	//淇敼鍩庡競鍚庡埛鏂板垪琛�
	g_page = 1;
	get_list();
}
function check_show(_id){
	check_show1(_id);
	show_add();
}

function show_packages(_arr){
	_flag = _arr;
	g_flaga = -1;
	$('.order_addiv1').css("background","");
	for(var a = 1;a<4;a++){
		$('#page'+a).css('display','none');
		$('#cosli'+a+' span').removeClass('order_span');
	}
	$('#page'+_arr).css('display','');
	$('#cosli'+_arr+' span').addClass('order_span');
}
function funNav(){
	if($('.AllNav').css('right') != '-2px'){
		$('.AllNav').animate({right:"-2px"},500);
	}else{
		$('.AllNav').animate({right:"-101px"},500);
	}
}
//打开提示框
function Uconfirm(arr){
	var message = arr;
	var obj = $('.uni_content');
	var cont = "<div id='fade' class='black_overlay'></div>";
	cont += "<div id='light' class='white_content'>";
	cont += "<div class='confTishi'><img src='images/tishi_05.png' alt='提示' class='confImg'><span class='confFont1'>提示</span></div>"
	cont += "<div class='confDiv'><span class='confFont'>"+message+"</span></div>"
	cont += "<div class='confClose' onClick='UconfirmClose()'>好</div></div>"
	obj.append(cont);
	$('#light').show();
	$('#fade').show();
}
//关闭提示框
function UconfirmClose(){
	$('#light').remove();
	$('#fade').remove();
}
//打开提示框
function Uconfirm2(arr){
	var message = arr;
	var obj = $('.page');
	var cont = "<div id='fade2' class='black_overlay'></div>";
	cont += "<div id='light2' class='white_content'>";
	cont += "<div class='confTishi'><img src='images/tishi_05.png' alt='提示' class='confImg'><span class='confFont1'>提示</span></div>"
	cont += "<div class='confDiv'><span class='confFont'>"+message+"</span></div>"
	cont += "<div class='confClose' onClick='UconfirmClose2()'>好</div></div>"
	obj.append(cont);
	$('#light2').show();
	$('#fade2').show();
}
//关闭提示框
function UconfirmClose2(){
	$('#light2').remove();
	$('#fade2').remove();
	location.href='index.php?uid=1';
}
//加入淘号吧
//套餐选择页面
var ant = true;//1s动画延时加载，在1s后才能继续点击操作
var heyuePack = 24;//12月合约 24月合约 36月合约
var arrHYpack = [12,36,24];
var heyuePrice = 66;//合约套餐
var arrHYP = [];
arrHYP.push({'id':66,'talkTime':"160",'flow':"220MB",'sms':"50",'mms':"5",'chargePerM':"0.20元/分钟"});
arrHYP.push({'id':96,'talkTime':"240",'flow':"340MB",'sms':"80",'mms':"10",'chargePerM':"0.15元/分钟"});
arrHYP.push({'id':126,'talkTime':"320",'flow':"450MB",'sms':"120",'mms':"15",'chargePerM':"0.15元/分钟"});
arrHYP.push({'id':156,'talkTime':"420",'flow':"570MB",'sms':"150",'mms':"17",'chargePerM':"0.15元/分钟"});
arrHYP.push({'id':186,'talkTime':"510",'flow':"720MB",'sms':"180",'mms':"20",'chargePerM':"0.15元/分钟"});
arrHYP.push({'id':226,'talkTime':"700",'flow':"850MB",'sms':"220",'mms':"25",'chargePerM':"0.15元/分钟"});
arrHYP.push({'id':286,'talkTime':"900",'flow':"1.1GB",'sms':"280",'mms':"30",'chargePerM':"0.15元/分钟"});
arrHYP.push({'id':386,'talkTime':"1250",'flow':"1.6GB",'sms':"380",'mms':"40",'chargePerM':"0.15元/分钟"});
arrHYP.push({'id':586,'talkTime':"1950",'flow':"2.5GB",'sms':"580",'mms':"65",'chargePerM':"0.15元/分钟"});
arrHYP.push({'id':886,'talkTime':"3000",'flow':"4GB",'sms':"880",'mms':"95",'chargePerM':"0.15元/分钟"});
		var col = -1;/*颜色选择
					  * 5s 0-灰色   1-银色
					  * 5c 0-白色   1-红色 2-黄色 3-蓝色 4-绿色
					  * note3 0-白色 1-黑色
					  * */
		var team = -1;//合约选择  暂时为空
		var pack = -1;//套餐选择
		var num = -1;//号码选择
		//颜色选择
		$('#byCol .autoDiv3').click(
			function(){
				var ant = $('#byCol .autoDiv3').index(this);
				$('#byCol .autoDiv3').removeClass('byChoice');
				if(col == -1){
					$('#byCol .autoDiv3:eq('+ant+')').addClass('byChoice');
					col = ant;
				}else{
					if(col == ant){
						col = -1;
						return;
					}else{
						$('#byCol .autoDiv3:eq('+ant+')').addClass('byChoice');
						col = ant;
					}
				}
			}
		);
		//颜色选择5s
		$('#byCol_s .autoDiv3').click(
			function(){
				var ant = $('#byCol_s .autoDiv3').index(this);
				if( ant == 0){
					$('#byRom .autoDiv').show();
				}else if( ant == 1){
					$('#byRom .autoDiv:eq(1)').hide();	
				}
				$('#byCol_s .autoDiv3').removeClass('byChoice');
				if(col == -1){
					$('#byCol_s .autoDiv3:eq('+ant+')').addClass('byChoice');
					col = ant;
				}else{
					if(col == ant){
						col = -1;
						return;
					}else{
						$('#byCol_s .autoDiv3:eq('+ant+')').addClass('byChoice');
						col = ant;
					}
				}
			}
		);
		
		$('#byPack .autoDiv2').click(
			function(){
				if(rom == -1)
				{
					Uconfirm('请先选择机型','mymsg');
					return false;
				}
				$('#fade').show();
				$('#light').show();
				//$('.autoDiv2:eq(1)').html(heyuePrice+"元合约");
				g_t = true;
				
				if(rom == 0 && g_p == 0)
				{
					arrHYpack[1] = 30;
					$('#showImgv').html("30月合约");
					if(heyuePack == 36)heyuePack = 30;
				}
				else
				{
					arrHYpack[1] = 36;
					$('#showImgv').html("36月合约");
					if(heyuePack == 30)heyuePack = 36;
				}
				var pos = parseInt($('#areaHY').css('left'));
				pos = -488;
				$('#areaHY').css('left',pos+'px');
				heyuePrice = arrHYP[2].id;
					//alert(_ind);
					fillInfo(arrHYP[2]);
					get_contract(rom,heyuePack,heyuePrice);//获得套餐详细
			}
		);
		$('.Cinfo-btns .info-btn-l').click(
			function(){
				$('#fade').hide();
				$('#light').hide();
				$('.autoDiv2:eq(1)').html(heyuePrice+"元合约");
				$('#byPack .autoDiv2').addClass('byChoice');
			}
		);
		$('.Cinfo-btns .info-btn-r').click(
				function(){
					$('#fade').hide();
					$('#light').hide();
				}
			);
		//每个页面加入导航层
		$('.footNav-div1').click(
				function(){
					if( $('.footNav-div2').css('display') == 'none'){
						$('.footNav-div1-img').attr('src',"images/qietu_37.png")
						$('.footNav-div2').show();
					}else{
						$('.footNav-div1-img').attr('src',"images/qietu_36.png")
						$('.footNav-div2').hide();
					}
					
				}
			);
			$('.footNav-div2-dr').click(
				function(){
					$('#navWX-b').show();
					$('#navWX-w').show();
				}
			);
			$('.navBtnQ').click(
				function(){
					$('#navWX-b').hide();
					$('#navWX-w').hide();
				}
			);
		//合约套餐切换66-96-126-
		$('.toLeft').click(
			function(){
				if(!ant){
					return;
				}
				var pos = parseInt($('#areaHY').css('left'));
				if(pos >= 0){
					pos = pos;
				}else{
					pos = pos + 244;
				}
				ant = false;//延时标识
				$('#areaHY').css('left',pos+'px');
				setTimeout(function(){
					ant = true;
					var _ind = parseInt($('#areaHY').css('left').replace(/[^·0-9]{1,}/g,''))/244;//0-9对应数组合约对象
					heyuePrice = arrHYP[_ind].id;
					//alert(_ind);
					fillInfo(arrHYP[_ind]);
					get_contract(rom,heyuePack,heyuePrice);//获得套餐详细
				},800);
			}
		);


		$('.toRight').click(
			function(){
				if(!ant){
					return;
				}
				var pos = parseInt($('#areaHY').css('left'));
				if(pos <= -2196){
					pos = pos;
				}else{
					pos = pos - 244;
				}
				ant = false;
				$('#areaHY').css('left',pos+'px');
				setTimeout(function(){
					ant = true;
					var _ind = parseInt($('#areaHY').css('left').replace(/[^·0-9]{1,}/g,''))/244;//0-9对应数组合约对象
					heyuePrice = arrHYP[_ind].id;
					//alert(_ind);
					fillInfo(arrHYP[_ind]);
					get_contract(rom,heyuePack,heyuePrice);//获得套餐详细
				},800);
			}
		);
		//12月 24月 30月切换
		$('.showImg').click(
			function(){
				var ant = parseInt($('.showImg').index($(this)));
				$('.layTitH2 div').removeClass('navLineLay');
				$(this).addClass('navLineLay');
				heyuePack = arrHYpack[ant];
				get_contract(rom,heyuePack,heyuePrice);//获得套餐详细
			}
		);
//
function closeBtns(){
	$('#newNum').hide();
	$('#fade').hide();
}
//合约套餐信息填充
function fillInfo(obj){
	var obj = obj;
	$('#talkTime').html(obj.talkTime);
	$('#flow').html(obj.flow);
	$('#sms').html(obj.sms);
	//$('#mms').html(obj.mms);
	$('#chargePerM').html(obj.chargePerM);
}
//打开提示框
function Uconfirm(arr,id){
	var message = arr;
	var _id = id;
	var obj = $('.page');
	var cont = "<div id='lay2' class='black_overlay'></div>";
	cont += "<div id='lay1' class='white_content2'>";
	cont += "<div class='confTishi1'><img src='images/tishi_05.png' alt='提示' class='confImg'><span class='confFont1'>提示</span></div>"
	cont += "<div class='confDiv1'><span class='confFont'>"+message+"</span></div>"
	cont += "<div class='confClose1' id='"+_id+"' onClick='UconfirmClose(this.id)'>好</div></div>"
	obj.append(cont);
	$('#lay2').show();
	$('#lay1').show();
}
//关闭提示框
function UconfirmClose(id){
	var _id = id;
	$('#lay2').remove();
	$('#lay1').remove();
	$('#'+_id).focus();
}

//获得套餐详细
function get_contract(m,y,t)
{
	if(m == 0)
	{
		m = 16;
	}
	else
	{
		if(m == 1)
		{
			m = 32;
		}
		else
		{
			m = 64;
		}
	}
	$.getJSON("ajax/get_contract.php",{p:g_p,m:m,y:y,t:t},
	function (json){
		if(json.err == "1")
		{
			Uconfirm(json.errinfo,'mymsg');
			return false;
		}
		else
		{
			//$('#hyPrice').html("￥"+json.bao);
			//$('#yhPrice').html("￥"+json.info[0]);
			//$('#ycPrice').html("￥"+json.info[1]);
			$('#fyPrice').html("￥"+json.info[2]);
			//g_p_price = parseInt(json.info[0]);
			g_p_price = parseInt(json.bao);
			g_price = g_p_price + g_n_price;
			$('#ipRprice').html(g_price);
		}
	});
}

function gradeChange(val,uid,domain,appkey){
	var val = val;//0-iphone 5s  1-iphone 5c  2-note 3
	//window.location = "http://www.baidu.com";
	if(val == 0)
	{
		location.href='mChoice5s.php?uid='+uid+'&domain='+domain+'&appkey='+appkey;
	}
	else
	{
		if(val == 1)
		{
			location.href='mChoice5c.php?uid='+uid+'&domain='+domain+'&appkey='+appkey;
		}
		else
		{
			location.href='mChoicenote3.php?uid='+uid+'&domain='+domain+'&appkey='+appkey;
		}
	}
}


var g_page = 1;//页码
var g_next = true;//是否有下页
var g_diy = 0;//是否DIY
//var _index = -1;
var g_num = '';
var g_n_price = 0;//号码价格
var g_p_price = 0;//手机价格
var g_price = 0;//最后价格
var g_phone_code = '';//绑定号码
var g_uuid = '';
var g_mid = '';

function set_phone()
{
	if($("#num").val() != "" && !isNaN($("#num").val()))
	{
		if($("#num").val().length < 2)
		{
			Uconfirm('请输入至少2位数字');
			return false;
		}
	}
	else
	{
		Uconfirm('请输入正确的数字');
		return false;
	}
	g_num = $("#num").val();
	g_diy = 1;
	get_list();
}

function choice_code(c,p)
{
	$.getJSON("ajax/checkMobile_m.php",{uid:1,phone_code:c},
	function (json){
		if(json.err == "1")
		{
			Uconfirm(json.errinfo);
			return false;
		}
		else
		{
			if(g_p == 2)
			{
				g_p_price = 200;
			}
			g_n_price = parseInt(p);
			g_price = g_p_price + g_n_price;
			$('#ipRprice').html(g_price);
			g_phone_code = c;
			$('#fade').hide();
			$('#newNum').hide();
			$('#byNum .autoDiv2').html(c);
			$('#byNum .autoDiv2').addClass('byChoice1');
			g_uuid = json.uuid;
			g_mid = json.mobileId;
		}
	});
}

//获取靓号列表
function get_list()
{
	$.getJSON("ajax/get_list_m.php",{type:g_diy,area:_index,page:g_page,num:g_num,low:heyuePrice},
	function (json){
		if(json.err == "1")
		{
			Uconfirm(json.errinfo);
			return false;
		}
		else
		{
			if(json.list.length == 0)
			{
				g_next = false;
				$("#showAllnum").empty();//清空表格
				$("#showAllnum").hide();
				$("#noShownm").show();
				return false;
			}
			if(json.list.length < 5)
			{
				g_next = false;
			}
			else
			{
				g_next = true;
			}
			$("#showAllnum").empty();//清空表格
			$("#showAllnum").show();
			$("#noShownm").hide();
			for(var i in json.list)
			{
				var str = "";
				str += "<div class='button_yuan button_margin' onclick=\"choice_code('"+json.list[i].phone_code+"','"+json.list[i].phone_fee+"')\">";
				if(g_diy == 1)
				{
					str += "<span class='fontcol div_margin'>"+get_c_code(json.list[i].phone_code,g_num)+"</span>";
				}
				else
				{
					str += "<span class='fontcol div_margin'>"+json.list[i].phone_code+"</span>";
				}
				/*if(parseInt(json.list[i].phone_fee) > 0)
				{
					var tmp = "<span>预存"+json.list[i].phone_fee+" </span>";
				}
				else
				{
					var tmp = "";
				}
				if(parseInt(json.list[i].phone_mon) > parseInt(heyuePrice))
				{
					str += "<span class='fontcol div_margin'>"+tmp+"保底消费"+json.list[i].phone_mon+"元</span>";
				}
				else
				{
					if(tmp != "")
					{
						str += "<span class='fontcol div_margin'>"+tmp+"</span>";
					}
				}*/
				str += "<span class='fontcol div_margin'>保底消费"+json.list[i].phone_mon+"元 <span>"+json.list[i].area_code+" </span></span>";
				str += "</div>";
				$("#showAllnum").append(str);
			}
		}
	});
}
//获取上一页列表
function goto_pre()
{
	if(g_page > 1)
	{
		g_page = g_page - 1;
		g_next = true;
		get_list();
	}
}
//获取下一页列表
function goto_next()
{
	if(g_next)
	{
		g_page = g_page + 1;
		get_list();
	}
}



//改变号码颜色
function get_c_code(code,num)
{
	var ostr = num;
	var str = "";
	var arr2=code.split(ostr);
	str = arr2[0];
	for(var i = 1;i<arr2.length;i++)
	{
		str += "<span class='choic_col'>"+ostr+"</span>"+arr2[i];
	}

	return str;
}